import cv2
import pandas as pd
import csv

def csv_get_num(csv_path, label_num):
    data = pd.read_csv(csv_path)
    num = len(data[data.label_num== label_num])
    return num

def img_append(csv_path, label, label_num, train_test, data):
    filename = label+str(csv_get_num(csv_path, label_num))+'.jpg'
    # print(filename)
    cv2.imwrite('data/'+train_test+'/'+filename, data)

    with open(csv_path, "a+") as csvfile:
        # print(filename)
        writer = csv.writer(csvfile)
        writer.writerow([filename, label_num])

def csv_init(csv_path):
    with open(csv_path,"w") as csvfile: #a+
        writer = csv.writer(csvfile)
        writer.writerow(['filename', 'label_num'])
    with open(csv_path,"w") as csvfile: #a+
        writer = csv.writer(csvfile)
        writer.writerow(['filename', 'label_num'])


